package com.offcn.controller;

import com.offcn.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Description:
 * User:SHEN
 * Date:2021--06--08--18:39
 */
@Controller
//@ResponseBody 表示返回的值不再以json对象形式展现
public class TestController {

    /**
     * @param model 传值
     * @return
     */
    @RequestMapping("/index01")
    public String index01(Model model) {
        model.addAttribute("name", "马云");
        return "index01";
    }

    @RequestMapping("/index02")
    public String index02(Model model) {
        User user = new User("张三", 2, 99);
        model.addAttribute("user", user);

        Map map = new HashMap<>();
        map.put("id", 2);
        map.put("name", "李四");
        map.put("sex", "男");
        model.addAttribute("map", map);
        return "index02";
    }

    @RequestMapping("/index03")
    public String index03(Model model) {
        User user1 = new User("张三", 1, 89);
        User user2 = new User("lisa", 2, 29);
        User user3 = new User("iu", 3, 29);
        User user4 = new User("bb", 4, 49);
        List<User> userList = new ArrayList<>();
        userList.add(user1);
        userList.add(user2);
        userList.add(user3);
        userList.add(user4);
        model.addAttribute("users", userList);
        return "index03";
    }

    @RequestMapping("/index04")
    public String index04(Model model){
        model.addAttribute("name","shen");
        return "index04";
    }

    @RequestMapping("/index05")
    public String index05(Model model){
        model.addAttribute("flag","yes");

        model.addAttribute("menu","admin");
        model.addAttribute("manager","manager");
        return "index05";
    }
}
